﻿using MVC.Pager;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Web;
using System.Web.Mvc;
using 代码段.Models;

namespace 代码段.Controllers
{
    public class HomeController : Controller
    {
        //public ActionResult Index(ArticleModel model)
        //{

        //    model.ArticleList = new List<string>();

        //    var random = new Random();
        //    for (int i = 0; i < 100; i++)
        //    {
        //        model.ArticleList.Add(random.Next().ToString());
        //    }
        //    model.TotalCount = model.ArticleList.Count;
        //    model.ArticleList = model.ArticleList.Skip((model.Page - 1) * model.PageSize).Take(model.PageSize).ToList();

        //    return View(model);
        //}


        public async Task<ActionResult> Index(ArticleModel model)
        {
            model.ArticleList = new List<string>();
            var random = new Random();
            for (int i = 0; i < 100; i++)
            {
                model.ArticleList.Add(random.Next().ToString());
            }
            model.TotalCount = model.ArticleList.Count;
            model.ArticleList = await Task.Run(() => model.ArticleList.Skip((model.Page - 1) * model.PageSize).Take(model.PageSize).ToList());

            return View(model);
        }



        public ActionResult About()
        {
            ViewBag.Message = "Your application description page.";

            return View();
        }

        public ActionResult Contact()
        {
            ViewBag.Message = "Your contact page.";

            return View();
        }
    }
}